import { BeError, BeSuccess } from './response';

interface ResponseDataType<T = any> {
  isError: boolean;
  message?: string;
  data?: T;
}

/**
 * 包装接口调用成功异常结果
 * @param isError 是否为错误
 * @param data 返回结果
 * @param message 错误消息
 */

export const packingResult = (result: ResponseDataType) => {
  const { isError, data } = result;
  if (isError) {
    return BeError(result.message, 9999, false);
  }
  return BeSuccess(data);
};
